var fs = require('fs');

function FileObject(filename) {
    this.filename = (filename) ? filename : '';
    this.file_exists = function(callback) {
        console.log('About to open: ' + this.filename);
        fs.open(this.filename, 'r', (err, handle) => {
            if(err) {
                console.log(`Can't open: ` + this.filename);
                callback(err);
                return;
            }
            fs.close(handle, function() {});
            callback(null, true);
        })
    }
}

var fo = new FileObject('file_that_does_not_exists'); // new FileObject('./src/chapter03/info.txt'); 
fo.file_exists((err, ret) => {
    if(err) {
        console.log(JSON.stringify(err));
        return;
    }
    if(ret) console.log("file exists");
    else console.log(`file doesn't exist`);
})